home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / nan_news / toolkit / minter.mac < prev    next >
Text File  |  1991-06-14  |  10KB  |  325 lines

  1. ; File......: MINTER.MAC (MASM 5.1)
  2. ; Author....: David Minter
  3. ; Date......: $Date:   14 Jun 1991 19:55:24  $
  4. ; Revision..: $Revision:   1.1  $
  5. ; Log file..: $Logfile:   E:/nanfor/src/minter.mav  $
  6. ; This is an original work by David Minter and is placed in the
  7. ; public domain.
  8. ;
  9. ; Modification history:
  10. ; ---------------------
  11. ;
  12. ; $Log:   E:/nanfor/src/minter.mav  $
  13. ;  
  14. ;     Rev 1.1   14 Jun 1991 19:55:24   GLENN
  15. ;  Minor edit to file header
  16. ;  
  17. ;     Rev 1.0   01 Apr 1991 01:04:00   GLENN
  18. ;  Nanforum Toolkit
  19. ;  
  20.  
  21.  
  22. ; Some Equates
  23.  
  24. ;       DOS interrupts for file management
  25.  
  26. OPENFILE        equ     03dh
  27. CLOSEFILE       equ     03eh
  28. READFILE        equ     03fh
  29. WRITEFILE       equ     040h
  30. DELETEFILE      equ     041h
  31. SEEKFILE        equ     042h
  32.  
  33.  
  34. ;----------------------------------------------------------------------------
  35. ;       @SAVE   -       save registers on the stack
  36. ;----------------------------------------------------------------------------
  37. @SAVE   macro   r1,r2,r3,r4,r5,r6,r7,r8,r9
  38.  
  39.         IRP     Reg,<r1,r2,r3,r4,r5,r6,r7,r8,r9>
  40.                 IFNB    <Reg>
  41.                         push    Reg
  42.                 ENDIF
  43.         endm
  44. endm
  45.  
  46. ;----------------------------------------------------------------------------
  47. ;       @RESTORE        -       restore registers from stack
  48. ;----------------------------------------------------------------------------
  49. @RESTORE macro  r1,r2,r3,r4,r5,r6,r7,r8,r9
  50.  
  51.         IRP     Reg,<r9,r8,r7,r6,r5,r4,r3,r2,r1>
  52.                 IFNB    <Reg>
  53.                         pop     Reg
  54.                 ENDIF
  55.         endm
  56. endm
  57.  
  58. ;----------------------------------------------------------------------------
  59. ;       @DOSREQ -       DOS function request using INT 21h
  60. ;----------------------------------------------------------------------------
  61. @DOSREQ macro   function
  62.  
  63.         mov     ah,function
  64.         int     21h
  65.  
  66. endm
  67.  
  68.  
  69. ;----------------------------------------------------------------------------
  70. ;       @CALL   -       call a procedure
  71. ;----------------------------------------------------------------------------
  72. @CALL   macro procedure,r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14
  73.  
  74.         _COUNT_ = 0
  75.  
  76.         EXTRN   procedure:far
  77.  
  78.         IRP     REG,<r1,r2,r3,r4,r5,r6,r7,r8,r9,r10,r11,r12,r13,r14>
  79.                 IFNB    <REG>
  80.                         _COUNT_ = _COUNT_ + 1
  81.                         push REG
  82.                 ENDIF
  83.         endm
  84.  
  85.         call    procedure
  86.         if _COUNT_
  87.                 add     sp,_COUNT
  88.         endif
  89.  
  90. endm
  91.  
  92. ;----------------------------------------------------------------------------
  93. ;       @BEGIN  -       Initialize a procedure macro
  94. ;----------------------------------------------------------------------------
  95. @BEGIN  macro   procedure
  96.  
  97. .code
  98.  
  99.         public  procedure
  100.         procedure proc far
  101.  
  102. endm
  103.  
  104. ;----------------------------------------------------------------------------
  105. ;       @END    -       end a procedure
  106. ;----------------------------------------------------------------------------
  107. @END    macro   procedure
  108.         procedure       endp
  109.                 end
  110.  
  111. endm
  112.  
  113. ;----------------------------------------------------------------------------
  114. ;       @PARINFO   -    get information about type of parameter passed,
  115. ;                       or the number of paramters passed.  An integer is
  116. ;                       returned in the AX register that denotes the type 
  117. ;                       of paramter passed                               
  118. ;----------------------------------------------------------------------------
  119. @PARINFO macro  _param
  120.  
  121.         EXTRN   __parinfo
  122.  
  123.         mov     ax,_param
  124.         push    ax
  125.         call    __parinfo
  126.         add     sp,2
  127.  
  128. endm
  129.  
  130. ;----------------------------------------------------------------------------
  131. ;       @PARINFA   -    get information about type of an array element, or
  132. ;                       the number of elements in the array passed.  An
  133. ;                       integer is returned in the AX register that denotes
  134. ;                       the type of an array element, or the number of 
  135. ;                       elements in the array
  136. ;----------------------------------------------------------------------------
  137. @PARINFA macro  _element,_param
  138.  
  139.         EXTRN   __parinfa
  140.  
  141.         mov     ax,_element
  142.         push    ax
  143.         mov     ax,_param
  144.         push    ax
  145.         call    __parinfa
  146.         add     sp,4
  147.  
  148. endm
  149.  
  150. ;----------------------------------------------------------------------------
  151. ;       @PARC   -       get a string from Clipper into dx:ax
  152. ;----------------------------------------------------------------------------
  153. @PARC   macro   _param
  154.         
  155.         EXTRN   __parc:far
  156.  
  157.         mov     ax,_param       ;get paramter we want
  158.         push    ax              ;send to __parc
  159.         call    __parc          ;call it
  160.         add     sp,2            ;clear the stack
  161.                                 ;dx:ax now contains the address
  162.  
  163. endm
  164.  
  165. ;----------------------------------------------------------------------------
  166. ;       @PARCLEN   -       gets length of a string from Clipper in AX
  167. ;----------------------------------------------------------------------------
  168. @PARCLEN macro  _param
  169.  
  170.         EXTRN   __parclen:far
  171.  
  172.         mov     ax,_param
  173.         push    ax
  174.         call    __parclen
  175.         add     sp,2
  176.  
  177. endm
  178.  
  179. ;----------------------------------------------------------------------------
  180. ;       @PARCSIZ   -    get allocated size of a string from Clipper.  It
  181. ;                       returns an integer in the AX register
  182. ;----------------------------------------------------------------------------
  183. @PARCSIZ macro  _param
  184.  
  185.         EXTRN   __parcsiz:far
  186.  
  187.         mov     ax,_param
  188.         push    ax
  189.         call    __parcsiz
  190.         add     sp,2
  191.  
  192. endm
  193.  
  194. ;----------------------------------------------------------------------------
  195. ;       @PARDS   -      get a date string from clipper.  It returns a pointer
  196. ;                       to a string in the DX:AX regiters.  The string is in
  197. ;                       the format YYYYMMDD
  198. ;----------------------------------------------------------------------------
  199. @PARDS  macro   _param
  200.  
  201.         EXTRN   __pards:far
  202.  
  203.         mov     ax,_param
  204.         push    ax
  205.         call    __pards
  206.         add     sp,2
  207.  
  208. endm
  209.  
  210. ;----------------------------------------------------------------------------
  211. ;@PARNI -       gets an integer from clipper in the AX register
  212. ;----------------------------------------------------------------------------
  213. @PARNI  macro   _param
  214.  
  215.         EXTRN   __parni:far
  216.  
  217.         mov     ax,_param
  218.         push    ax
  219.         call    __parni
  220.         add     sp,2
  221.  
  222. endm
  223.  
  224. ;----------------------------------------------------------------------------
  225. ;@PARL  -       gets a logical from Clipper in the AX Register.  Logical .T.
  226. ;               will equal 1, logical .F. will equal 0
  227. ;----------------------------------------------------------------------------
  228. @PARL   macro   _param
  229.  
  230.         EXTRN   __parl:far
  231.  
  232.         mov     ax,_param
  233.         push    ax
  234.         call    __parl
  235.         add     sp,2
  236.  
  237. endm
  238.  
  239. ;----------------------------------------------------------------------------
  240. ;@PARNL -       gets a long value from Clipper in the DX:AX register
  241. ;----------------------------------------------------------------------------
  242. @PARNL  macro   _param
  243.  
  244.         EXTRN   __parnl:far
  245.  
  246.         mov     ax,_param
  247.         push    ax
  248.         call    __parnl
  249.         add     sp,2
  250.  
  251. endm
  252.  
  253. ;----------------------------------------------------------------------------
  254. ;       @RETC   -       return a string to Clipper
  255. ;----------------------------------------------------------------------------
  256. @RETC    macro    _param
  257.  
  258.     EXTRN    __retc:FAR
  259.  
  260.     mov    dx, seg _param
  261.     mov    ax, offset _param
  262.     push    dx
  263.     push    ax
  264.     call    __retc
  265.     add    sp, 4
  266.  
  267. endm
  268.  
  269. ;----------------------------------------------------------------------------
  270. ;    @RETL    -    return a logical to Clipper
  271. ;----------------------------------------------------------------------------
  272. @RETL    macro    _param
  273.  
  274.     EXTRN    __retl:FAR
  275.  
  276.     mov    ax,_param
  277.     push    ax
  278.     call    __retl
  279.     add    sp, 2
  280.  
  281. endm
  282.  
  283. ;----------------------------------------------------------------------------
  284. ;    @RET    -    return a Nil to clipper
  285. ;----------------------------------------------------------------------------
  286. @RET    macro    
  287.  
  288.     EXTRN    __ret:FAR
  289.     call    __ret
  290.  
  291. endm
  292.  
  293. ;----------------------------------------------------------------------------
  294. ;       @FOPEN  -       Open a file, requires pointer to name, open mode
  295. ;                       returns a handle in AX, or -1 for error.  Open mode
  296. ;                       defaults to 0 if not passed
  297. ;----------------------------------------------------------------------------
  298. @FOPEN  macro   _segment,_offset,_openmode
  299.         local   _SkipError              ;local label used in macro only
  300.  
  301.         @SAVE   ds,dx                   ;save DS and DX
  302.  
  303.         mov     ax,_segment             ;get the segment of the file name
  304.         mov     ds,ax                   ;into DS as required by DOS
  305.  
  306.         mov     dx,_offset              ;get offset of filename as required
  307.  
  308.         IFNB    _openmode               ;if openmode passed
  309.           mov   al,_openmode            ;use it
  310.         ELSE                            ;else
  311.           xor   al,al                   ;use 0 as the default mode
  312.         ENDIF
  313.  
  314.         @DOSREQ OPENFILE                ;handle now in AX, or error code
  315.  
  316.         @RESTORE        ds,dx           ;restore DS and DX
  317.  
  318.         jnc     _SkipError              ;if no carry flag, don't change AX
  319.         mov     ax,-1                   ;else return -1 for error
  320.         _SkipError:
  321.  
  322. endm
  323. 
  324.